package cpagraph;

import java.util.Vector;


public class Edge
{
	double weight;
	Node a;
	Node b;
	
	/**
	 * Initializes new Edge object.
	 * 
	 * @param a this edge is incident to node a
	 * @param b this edge is incident to node a
	 * @param w weight of this edge 
	 */
	public Edge(Node a, Node b, double w)
	{
		this.a = a;
		this.b = b;
		this.weight = w;
	}
	
	/**
	 * @param n some node
	 * @return true, if node is one of the edge's nodes, false otherwise
	 */
	public boolean isIncidentTo(Node n)
	{
		return (a.equals(n) || b.equals(n));
	}
	
	/**
	 * @param bus
	 * @return true, if both nodes of the edge are assigned to bus, false otherwise
	 */
	public boolean isAssignedTo(Bus bus)
	{
		return a.isAssignedTo(bus) && b.isAssignedTo(bus);
	}
	
	/**
	 * @return list of bus lines going on this edge
	 */
	public Vector<Bus> assignedTo()
	{
		Vector<Bus> v = new Vector<Bus>();
		
		for (int i = 0; i < b.busses.size(); i++)
		{
			Bus bus = b.busses.elementAt(i);
			
			if (a.busses.contains(bus))
			{
				v.add(bus);
			}
		}
		
		return v;
	}
}
